/*
Copyright 2008, 2009 Joonas Lehtolahti

This file is part of Shared Datatypes and Utilities.

Shared Datatypes and Utilities is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Shared Datatypes and Utilities is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Shared Datatypes and Utilities.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _LINKEDLIST_H_
#define _LINKEDLIST_H_

#include "shared_def.h"

/* LinkedList node */
typedef struct _llistnode
{
  void *               x;
  struct _llistnode *  prev;
  struct _llistnode *  next;
  struct _llist     *  list;
}ListNode;

/* LinkedList */
typedef struct _llist
{
  ListNode		*first;
  ListNode		*last;
  unsigned int	 nodes;
}LinkedList;


/* LinkedList creation function */
DLLEXPORT(LinkedList*) LLcreate(void);

/* LinkedList freeing function */
DLLEXPORT(void) LLdelete(LinkedList*,FREEFUNC*);

/* LinkedList add item to start */
DLLEXPORT(ListNode*) LLaddFirst(LinkedList*,void*);

/* LinkedList add item to end */
DLLEXPORT(ListNode*) LLaddLast(LinkedList*,void*);

/* LinkedList add item before node */
DLLEXPORT(ListNode*) LLaddBefore(ListNode*,void*);

/* LinkedList add item after node */
DLLEXPORT(ListNode*) LLaddAfter(ListNode*,void*);

/* LinkedList remove specific node */
DLLEXPORT(void*) LLdelNode(ListNode*);

/* LinkedList remove item from start */
DLLEXPORT(void*) LLdelFirst(LinkedList*);

/* LinkedList remove item from end */
DLLEXPORT(void*) LLdelLast(LinkedList*);

/* Merge two LinkedList into one, deleting the second one */
DLLEXPORT(LinkedList*) LLmerge(LinkedList *first, LinkedList *second);

#endif
